﻿<div class="form-horizontal" ms-controller="TXL">
    <div class="form-group">
        <label class="col-xs-2 control-label">姓名</label>
        <div class="col-xs-9">
            <input type="text" value="" class="form-control szhl_require" ms-duplex="modelData.LXName" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">联系方式（手机）</label>
        <div class="col-xs-9">
            <input type="text" value="" class="form-control szhl_require  szhl_Int" ms-duplex="modelData.LXHM" />
        </div>
    </div>
    
    <div class="form-group">
        <label class="col-xs-2 control-label">邮箱</label>
        <div class="col-xs-9">
            <input type="text" value="" class="form-control" ms-duplex="modelData.LXMail" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">类型</label>
        <div class="col-xs-2">
            <select class="form-control" ms-duplex="modelData.TagName">
                <option ms-repeat-item="ColumnData" ms-attr-val="item.TypeNO" ms-attr-selected="item.TagName==modelData.TagName?'selected':''">{{item.TagName}}</option>
            </select>
        </div>
        <div class="col-xs-2"><button class="btn btn-primary btn-block" ms-click="showTag()">添加分类</button></div>
        <div class="col-xs-5 addtag" style="display:none">
            <div class="input-group">
                <input type="text" ms-duplex="TagData.TagName" class="form-control">
                <span class="input-group-btn">
                    <button class="btn btn-success" ms-click="addTag()">确定</button>
                    <button class="btn btn-danger" ms-click="qxTag()">取消</button>
                </span>
            </div>

        </div>
    </div>
    <div class="form-group">
        <label class="col-xs-2 control-label">备注</label>
        <div class="col-xs-9">
            <input type="text" value="" class="form-control" ms-duplex="modelData.LXRemark" />
        </div>
    </div>
</div>
<script>
    var tempmodel = avalon.define({
        $id: "TXL",
        iswf: false,//是否属于流程表单
        ColumnData: [],
        modelData: { "LXName": "", "LXHM": "", "TagName": "", "LXMail": "", "LXRemark": "" },
        TagData: { "Model": "TXL", "TagName": "" },
        inittemp: function (strId) {
            $.getJSON('/API/FTAPI.ashx?Action=GETTAGLIST', { P1: "TXL" }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    tempmodel.ColumnData = resultData.Result;
                    if (!strId) {
                        if (resultData.Result.length > 0) {
                            tempmodel.modelData.TagName = resultData.Result[0].TagName;
                        }
                        ComFunJS.initForm();
                    }
                }
            })
            if (strId) {
                //编辑加载数据
                $.getJSON('/API/FTAPI.ashx?Action=GETTXLMODEL', { P1: strId }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        tempmodel.modelData = resultData.Result;
                        setTimeout("ComFunJS.initForm()", 500)
                    }
                })
            }
        },//初始化
        SaveData: function (btdom, piid) {
            var data = tempmodel.modelData.$model;
            var modelValue = JSON.stringify(data);
            $.post("/API/FTAPI.ashx?ACTION=ADDTXL", { P1: modelValue }, function (result) {
                var jsonresult = $.parseJSON(result)
                btdom.removeClass("disabled").find("i").hide();
                if ($.trim(jsonresult.ErrorMsg) == "") {
                    ComFunJS.winsuccessnew("操作成功");
                }
            });
        }, addTag: function () {
            if (!tempmodel.TagData.TagName)
            {
                alert("请输入分类");
                return;
            }
            var data = tempmodel.TagData.$model;
            var modelValue = JSON.stringify(data);
            $.post("/API/FTAPI.ashx?ACTION=ADDTAG", { P1: modelValue }, function (result) {
                var jsonresult = $.parseJSON(result)
                if ($.trim(jsonresult.ErrorMsg) == "") {
                    tempmodel.ColumnData.push(jsonresult.Result);
                    tempmodel.modelData.TagName = jsonresult.Result.TagName;
                    ComFunJS.winsuccess("操作成功");
                    $(".addtag").hide().prev().show();
                }
            });
        }, qxTag: function () {
            $(".addtag").hide().prev().show(); 
        }, showTag: function () {
            $(".addtag").show().prev().hide();
        }
    });

</script>